package com.jbm;

/**
 * Created by root on 18-6-1.
 */
public class Guard
{
	static byte[] getOpenCMD(int gid,int cid)
	{
		byte[] open = {0x01, 0x30, 0x33, 0x34, 0x30, 0x30, 0x30, 0x30, 0x4A, 0x41,
				0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
				0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
				0x30, 0x31, 0x02,
//					0x38, 0x31, 0x41, 0x35,
				0x30, 0x30, 0x30, 0x30,
				0x0d
		};

		byte code[] = String.format("%02X",1<<(cid%8)).getBytes();
		byte gd[] = String.format("%04X",gid).getBytes();

		open[1] = gd[1];
		open[2] = gd[2];
		open[3] = gd[3];

		open[10+(cid/8)*2] = code[0];
		open[10+(cid/8)*2+1] = code[1];

		return open;
	}

	static byte[] getBlackCMD(String order, int gid, int cid ) //order in "join","remove"
	{
		byte[] open = {0x01, 0x30, 0x33, 0x34, 0x30, 0x30, 0x30, 0x30, 0x48, 0x00,
				0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x02,
				0x30, 0x30, 0x30, 0x30,
				0x0d
		};

		if ( "join".equals(order) )
			open[9] = 0x55;
		else if ( "remove".equals(order) )
			open[9] = 0x57;
		else
			return null;

		byte code[] = String.format("%08X",cid).getBytes();
		byte gd[] = String.format("%04X",gid).getBytes();

		open[1] = gd[1];
		open[2] = gd[2];
		open[3] = gd[3];

		System.arraycopy(code,0,open,10,8);

		return open;
	}
}
